package com.coding.controller;

import com.coding.dto.RestBean;
import com.coding.entity.Conversation;
import com.coding.entity.vo.SessionVO;
import com.coding.service.ConversationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Cynicism
 * @version 1.0
 * @project DyApp
 * @description
 * @date 2024/7/3 13:38:06
 */
@RestController
@RequestMapping("/conversation")
//@CrossOrigin
public class ConversationController {

    @Resource
    private ConversationService conversationService;

    @PostMapping("/insert")
    public RestBean<String> insertConversation(@RequestParam String userId1, @RequestParam String userId2) {
        if (userId1 == null || userId2 == null || userId1.isEmpty() || userId2.isEmpty()){
            return RestBean.failure(400,"参数错误");
        }


        return conversationService.insertConversation(Long.parseLong(userId1), Long.parseLong(userId2));
    }

    @PostMapping("/delete")
    public RestBean<String> deleteConversation(@RequestParam String userId1, @RequestParam String userId2) {
        if (userId1 == null || userId2 == null || userId1.isEmpty() || userId2.isEmpty()){
            return RestBean.failure(400,"参数错误");
        }

        return conversationService.deleteConversation(Long.parseLong(userId1), Long.parseLong(userId2));
    }

    @GetMapping("/getConversationList")
    public RestBean<List<SessionVO>> getConversationList(String userId) {
        if (userId == null|| userId.isEmpty()){
            return RestBean.failure(400,"参数错误");
        }
        long l = Long.parseLong(userId);
        return conversationService.getConversationList(l);
    }
}
